package com.ruoyi.web.controller.oss;

import java.util.Arrays;
import java.util.List;
import jakarta.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.annotation.RepeatSubmit;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.oss.domain.SysOssConfig;
import com.ruoyi.oss.service.ISysOssConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 对象存储配置Controller
 *
 * @author ruoyi
 * @date 2023-02-08
 */
@RestController
@RequestMapping("/oss/ossConfig")
public class SysOssConfigController extends BaseController
{
    @Autowired
    private ISysOssConfigService sysOssConfigService;

    /**
     * 查询对象存储配置列表
     */
    @PreAuthorize("@ss.hasPermi('oss:ossConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysOssConfig sysOssConfig)
    {
        startPage();
        QueryWrapper<SysOssConfig> sysOssConfigQueryWrapper = new QueryWrapper<>(sysOssConfig);
        List<SysOssConfig> list = sysOssConfigService.list(sysOssConfigQueryWrapper);
        return getDataTable(list);
    }

    /**
     * 导出对象存储配置列表
     */
    @PreAuthorize("@ss.hasPermi('oss:ossConfig:export')")
    @Log(title = "对象存储配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOssConfig sysOssConfig)
    {
        QueryWrapper<SysOssConfig> sysOssConfigQueryWrapper = new QueryWrapper<>(sysOssConfig);
        List<SysOssConfig> list = sysOssConfigService.list(sysOssConfigQueryWrapper);
        ExcelUtil<SysOssConfig> util = new ExcelUtil<SysOssConfig>(SysOssConfig.class);
        util.exportExcel(response, list, "对象存储配置数据");
    }

    /**
     * 获取对象存储配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('oss:ossConfig:query')")
    @GetMapping(value = "/{ossConfigId}")
    public AjaxResult getInfo(@PathVariable("ossConfigId") Long ossConfigId)
    {
        return success(sysOssConfigService.getById(ossConfigId));
    }

    /**
     * 新增对象存储配置
     */
    @PreAuthorize("@ss.hasPermi('oss:ossConfig:add')")
    @Log(title = "对象存储配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping
    public AjaxResult add(@RequestBody SysOssConfig sysOssConfig)
    {
        return toAjax(sysOssConfigService.save(sysOssConfig));
    }

    /**
     * 修改对象存储配置
     */
    @PreAuthorize("@ss.hasPermi('oss:ossConfig:edit')")
    @Log(title = "对象存储配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping
    public AjaxResult edit(@RequestBody SysOssConfig sysOssConfig)
    {
        return toAjax(sysOssConfigService.updateById(sysOssConfig));
    }

    /**
     * 删除对象存储配置
     */
    @PreAuthorize("@ss.hasPermi('oss:ossConfig:remove')")
    @Log(title = "对象存储配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        List<Long> list = Arrays.asList(ids);
        return toAjax(sysOssConfigService.removeByIds(list));
    }
}